/* 
 *  Incub - incubate your baby robot
 *  Copyright (C) 2008 Stanislaw Szymczyk
 *  e-mail: sszymczy@gmail.com   www: http://cogville.cog-lab.com
 *
 *  This file is part of Incub.
 *
 *  Incub is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Incub is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Incub.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
 
#include "World.h"
#include <iostream>

using std::string;
using std::vector;

World::World() {
	step = 0.0025;
}

void World::addEntity(Entity* e) {
	entities.push_back(e);
}

vector<Entity*>& World::getEntities() {
	return entities;
}

void World::addMaterial(Material* mat) {
	materials[mat->getName()] = mat;
}

Material* World::getMaterial(string name) {
	Material* mat = materials[name];
	if(!mat) throw Material::NoSuchMaterialException((char*)name.c_str());
	return mat;
}

void World::setStep(string& step) {
	this->step = atof(step.c_str());
}

float World::getStep() {
	return step;
}

World::~World() {
	std::cout << "destroying world: " << std::endl;
	for(std::map<string, Material*>::iterator material = materials.begin(); material != materials.end(); material++) {
		delete material->second;
	}	
	for(vector<Entity*>::iterator entity = entities.begin(); entity != entities.end(); entity++) {
		delete *entity;
	}	
}
